package com.westmarine.qr_hybris.tests;

import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.assertEquals;

import java.awt.AWTException;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.concurrent.TimeUnit;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.monte.media.math.Rational;
import org.monte.media.Format;
import org.monte.screenrecorder.ScreenRecorder;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

import static org.monte.media.AudioFormatKeys.*;
import static org.monte.media.VideoFormatKeys.*;

import com.westmarine.qr_hybris.util.Browser;
import com.westmarine.qr_hybris.util.Browser.DriverType;
import com.westmarine.qr_hybris.util.MethodAction.CardType;
import com.westmarine.qr_hybris.util.MethodAction;
import com.westmarine.qr_hybris.util.MethodAction.LoyaltyType;
import com.westmarine.qr_hybris.util.MethodUtil;

public class SmokeTestQAVNv1 {
	private ScreenRecorder screenRecorder;
	private WebDriver driver;
    public Select selectAddress;
    public Select selectState;
    public Select selectCard;
    public Select selectMonth;
    public Select selectYear;
    public Select selectCountry;
    public Select selectStore;
    public WebElement myWait;
    public WebElement search;
    
    public String username="vun@westmarine.com";
    public String password="Ilove12345678";
    
	
	@BeforeMethod
	public void beforeMethod() throws IOException, AWTException {
		Browser.setDriver(DriverType.IE);
		Browser.driver.manage().window().maximize();
		driver = Browser.driver;
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
		screenRecorder = MethodUtil.getScreenRecorder();
		screenRecorder.start();
	}
	
	@Test
	public void testCase_1A_HomePage(){
		//Verify the Home Page loads
		driver.get("qr-hybris.westmarine.net");
	}
	
	@Test
	public void testCase_2A_Register(){
		//Verify user registration without choosing any options in Join West Advantage Rewards section
  		String email = MethodUtil.uniqueEmailStr();
  		String password = "Ilove12345678";
  		String checkPwd = "Ilove12345678";
  		String firstName = "Vu" + (new Date()).getTime();
  		String lastName = "Nguyen";
  		String country = "United States";
  		String line1 = "899 Cameron Cir";
  		String line2 = "";
  		String townCity = "Milpitas";
  		String region = "California" ;
  		String postcode = "95035";
  		String phone = "2818185768";
  		if (Browser.typeDriver.equals("IE") && driver.getTitle().contains("Certificate"))
  			driver.get("javascript:document.getElementById('overridelink').click();");
  		MethodAction.registerEnterNewUser(driver, email, password, checkPwd, firstName, lastName, country, line1, line2, townCity, region, postcode, phone);
  		MethodAction.registerClickSubmitButton(driver);
  		assertTrue(driver.getPageSource().contains("West Advantage Rewards"));
	}
	
	@Test
	public void testCase_2C_Register(){
		//Verify user registration with Gold Membership  option in Join West Advantage Rewards section

  		String email = MethodUtil.uniqueEmailStr();
  		String password = "Ilove12345678";
  		String checkPwd = "Ilove12345678";
  		String firstName = "Vu" + (new Date()).getTime();
  		String lastName = "Nguyen";
  		String country = "United States";
  		String line1 = "899 Cameron Cir";
  		String line2 = "";
  		String townCity = "Milpitas";
  		String region = "California" ;
  		String postcode = "95035";
  		String phone = "2818185768";
  		MethodAction.registerEnterNewUser(driver, email, password, checkPwd, firstName, lastName, country, line1, line2, townCity, region, postcode, phone, true, true, LoyaltyType.GOLD);
  		MethodAction.registerClickSubmitButton(driver);
  		assertTrue(driver.getPageSource().contains("Upgrade to West Advantage Gold Rewards"));
  	}
	
	@Test
	public void testCase_2B_Register(){

  		String email = MethodUtil.uniqueEmailStr();
  		String password = "Ilove12345678";
  		String checkPwd = "Ilove12345678";
  		String firstName = "Vu" + (new Date()).getTime();
  		String lastName = "Nguyen";
  		String country = "United States";
  		String line1 = "899 Cameron Cir";
  		String line2 = "";
  		String townCity = "Milpitas";
  		String region = "California" ;
  		String postcode = "95035";
  		String phone = "2818185768";
  		MethodAction.registerEnterNewUser(driver, email, password, checkPwd, firstName, lastName, country, line1, line2, townCity, region, postcode, phone, true, true, LoyaltyType.SILVER);
  		MethodAction.registerClickSubmitButton(driver);
  		assertTrue(driver.getPageSource().contains("West Advantage Rewards: Silver"));
  	}
	
	@Test
	public void testCase_2D_Register(){
  		String email = MethodUtil.uniqueEmailStr();
  		String password = "Ilove12345678";
  		String checkPwd = "Ilove12345678";
  		String firstName = "Vu" + (new Date()).getTime();
  		String lastName = "Nguyen";
  		String country = "United States";
  		String line1 = "899 Cameron Cir";
  		String line2 = "";
  		String townCity = "Milpitas";
  		String region = "California" ;
  		String postcode = "95035";
  		String phone = "2818185768";
  		MethodAction.registerEnterNewUser(driver, email, password, checkPwd, firstName, lastName, country, line1, line2, townCity, region, postcode, phone, true, true, LoyaltyType.NO);
  		MethodAction.registerClickSubmitButton(driver);
  		assertTrue(driver.getPageSource().contains("West Advantage Rewards"));
  	}
	
	@Test
	public void testCase_2E_Register(){

  		String email = MethodUtil.uniqueEmailStr();
  		String password = "Ilove12345678";
  		String checkPwd = "Ilove12345678";
  		String firstName = "Vu" + (new Date()).getTime();
  		String lastName = "Nguyen";
  		String country = "United States";
  		String line1 = "899 Cameron Cir";
  		String line2 = "";
  		String townCity = "Milpitas";
  		String region = "California" ;
  		String postcode = "95035";
  		String phone = "2818185768";
  		MethodAction.registerEnterNewUser(driver, email, password, checkPwd, firstName, lastName, country, line1, line2, townCity, region, postcode, phone, true, true, LoyaltyType.NO);
  		MethodAction.registerClickSubmitButton(driver);
  		assertTrue(driver.getPageSource().contains("West Advantage Rewards"));
  	}
	
	
	
	@Test
	public void testCase_4A_Search(){
		//Verify user can perform a search
		MethodAction.search(driver, "short");
		Browser.driver.findElement(By.linkText("50 Per Page")).click();
        Select sortBy = new Select(Browser.driver.findElement(By.id("sortOptions1")));
        sortBy.selectByValue("topRated");
	}
	
	@Test
	public void testCase_5A_Store_Locator (){
		//Verify user can go to store locator and can perform a search 
		//and get results of the stores near user
		MethodAction.storeLocator(driver, "94133");
	    assertTrue("Sausalito)", driver.getPageSource().contains("West Marine Sausalito"));	    
	}
	
	@Test(enabled=false)
	public void testCase_6A_See_product_details(){
		//Verify user can see product details
		MethodAction.searchSku(driver, "12743415");
		String urlExpected="http://qr-hybris.westmarine.net/buy/columbia--men-s-bahama-ii-long-sleeve-shirt-white-s--12743415";	
		assertEquals(urlExpected, driver.getCurrentUrl());
	}
	
	@Test
	public void testCase_7A_See_Ratings_revies(){
		//Verify user can see star rating and read reviews on the product details page
		//if 7A pass --> 6A pass
		MethodAction.searchSku(driver, "12743415");
		String urlExpected="http://qr-hybris.westmarine.net/buy/columbia--men-s-bahama-ii-long-sleeve-shirt-white-s--12743415";	
		assertEquals(urlExpected, driver.getCurrentUrl());
		driver.findElement(By.className("pr-snippet-link")).click();
		assertTrue(driver.getPageSource().contains("Comments"));
	}
	
	
	@Test(enabled=false)
	public void testCase_8A_Check_out_as_a_guest(){
		//Verify user can start the checkout process
		//searchSkuAddToCartEnterMasterCardPlaceOrderAsGuest

		MethodAction.searchSkuAddToCartBachelorGoToCartGoToCheckout(driver, "13194626",1);
		MethodAction.loginAsGuest(driver, username);
		MethodAction.deliveryShippingAddreesEnterShippingAddress(driver, "United States",
				"firstN", "lastN", "8320", "", "Tempe", 
				"Arizona", "85284", "2818185768");
		MethodAction.deliveryShippingAddressContinueClick(driver);
		MethodAction.deliveryShippingMethodOptionSelect(driver, 1);
		MethodAction.deliveryShippingMethodContinueClick(driver);
		MethodAction.paymentMethodEnterNewCard(driver, CardType.Visa, "6011577019999920",
				"999","12","2015","Vu Nguyen", "11","11","11" );
		MethodAction.paymentMethodContinueClick(driver);
		MethodAction.paymentMethodEnterNewCard(driver, CardType.Visa, "4111111111111111",
				"999","12","2015","Vu Nguyen", "11","11","11" );
		MethodAction.paymentMethodContinueClick(driver);
		MethodAction.summaryPlaceOrderClick(driver);
		
		assertEquals("Thank you for your purchase", driver.findElement(By.xpath("//div[@id='content']/div[3]/h1")).getText());
	}
	
	@Test(enabled=true)
	public void testCase_8C_Check_out_as_returning_user() throws InterruptedException{
		//Verify user can start the checkout process

		MethodAction.searchSkuAddToCartBachelorGoToCartGoToCheckout(driver, "4235750",1);
		MethodAction.loginAsReturnCustomer(driver, username, password);
		MethodAction.deliveryShippingAddressContinueClick(driver);
		MethodAction.deliveryShippingMethodOptionSelect(driver, 1);
		MethodAction.deliveryShippingMethodContinueClick(driver);
		MethodAction.paymentMethodSelectCardUsedForLoggedInUser(driver, 1, "999");
		MethodAction.paymentMethodContinueClick(driver);
		Thread.sleep(1500);
		MethodAction.summaryPlaceOrderClick(driver);
		assertEquals("Thank you for your purchase", driver.findElement(By.xpath("//div[@id='content']/div[3]/h1")).getText());
	}
	
	@Test
	public void testCase_8D_Remove_item_out_of_cart(){
		//Verify user can remove item to cart
		MethodAction.searchSkuAddToCartBachelorGoToCart(driver, "11541851",4);
		MethodAction.cartProductQuantityUpdate(driver, 0, 2);
		assertEquals(2, MethodAction.cartGetProductQuantity(driver, 0));
		MethodAction.cartRemoveProduct(driver, 0);
		assertTrue(driver.getPageSource().contains("Product has been removed from your cart."));
		
	}
	
	@Test(enabled=true)
	public void testCase_8E_Update_quantity_cart(){
		//Verify user can add item to cart
		//If 8D pass 8E pass
		MethodAction.searchSkuAddToCartBachelorGoToCart(driver, "11541851",4);
		MethodAction.cartProductQuantityUpdate(driver, 0, 2);
		assertEquals(2, MethodAction.cartGetProductQuantity(driver, 0));
	}
	
	@Test(enabled=true)
	public void testCase_9A_Add_Shipping_Address() throws InterruptedException{
		//Verify user can start the checkout process

		MethodAction.searchSkuAddToCartBachelorGoToCartGoToCheckout(driver, "13194626",1);
		MethodAction.loginAsReturnCustomer(driver, username, password);
		MethodAction.deliveryEnterShippingAddressClick(driver);
		String firstName = "Vu" + (new Date()).getTime();
		MethodAction.deliveryShippingAddreesEnterShippingAddress(driver, "United States",
				firstName, "lastN", "8320", "", "Tempe", 
				"Arizona", "85284", "2818185768");
		MethodAction.deliveryShippingAddressContinueClick(driver);
		assertTrue(driver.getPageSource().contains(firstName));
	}
	
	@Test
	public void testCase_9B_Edit_Shipping_Address() throws InterruptedException{
		//Verify user can edit shipping address
		MethodAction.searchSkuAddToCartBachelorGoToCartGoToCheckout(driver, "13194626", 1);
		MethodAction.loginAsReturnCustomer(driver, username, password);
		driver.findElement(By.xpath("//div[@id='content']/div/div[2]/div[1]/div[3]/div[1]/form/label/ul/li[7]/a")).click();
		//MethodAction.deliveryShippingAddreesEnterShippingAddress(driver, "United States",
		//		"", " Ok", "", "", "", "California", "", "");
		Thread.sleep(2000);
		String expectedResult = "Vu" + (new Date()).getTime()%1000;
		driver.findElement(By.id("address.line1")).clear();
		driver.findElement(By.id("address.line1")).sendKeys(expectedResult);
		Thread.sleep(1000);
		driver.findElement(By.id("use-and-save-button")).click();
		//driver.findElement(By.xpath("//div[@id='content']/div[2]/div[1]/div[1]/a[1]")).click();
		Thread.sleep(5000);
		assertTrue(driver.getPageSource().contains(expectedResult));
		
	}
	
	@Test
	public void testCase_9C_Enter_Freight_Address() throws InterruptedException{
		//apparel sku = 8111312
		MethodAction.searchSkuAddToCartBachelorGoToCartGoToCheckout(driver, "4235750");
		MethodAction.loginAsReturnCustomer(driver, username, password);
		MethodAction.deliveryShippingAddressFreightForwardAddressClick(driver);
		Thread.sleep(1500);
		String firstName = "Vu" + (new Date()).getTime();
		MethodAction.deliveryShippingAddreesEnterFreightForwardAddress(driver, firstName, "Prodigious", 
							"United States", "firstName", "lastName", "line1", "", "Milpitas",
							"California", "95035", "2818185768", 
							"United States", "Vu", "destinationLastName",
							"destinationLine1", "", "Milpitas", "California", "94539", "8607965308");
		String expectedResult = driver.findElements(By.name("townCity")).get(1).getAttribute("value");
		MethodAction.deliveryShippingAddressContinueClick(driver);
		assertTrue(driver.getPageSource().contains(firstName));
		
	}
	
	@Test
	public void testCase_9D_ShipToStore() throws InterruptedException{
		//Verify user can select a ship to store on the shipping address step.
		MethodAction.login(driver, username, password);
		MethodAction.searchSkuAddToCartBachelorGoToCartGoToCheckout(driver, "13194626", 1);
		MethodAction.deliveryShippingAddressFindStoreClick(driver);
		Thread.sleep(1500);
		driver.findElement(By.id("storelocator-query")).sendKeys("29407");
	    driver.findElement(By.className("search")).click();
	    Thread.sleep(1500);
	    driver.findElement(By.id("West-Marine-Charleston29407")).
	    findElement(By.className("store-hours")).findElement(By.className("blue")).click();
	    driver.findElement(By.id("shipToStoreContactDiv")).findElement(By.name("shipToStoreContact")).sendKeys("5716682014");
	    driver.findElement(By.id("use_this_delivery_method")).click();
	    Thread.sleep(2000);
	    MethodAction.deliveryShippingAddressContinueClick(driver);
	    MethodAction.deliveryShippingMethodContinueClick(driver);
	    MethodAction.paymentMethodSelectCardUsedForLoggedInUser(driver,1 ,"999");
	    MethodAction.paymentMethodContinueClick(driver);
	    MethodAction.summaryPlaceOrderClick(driver);
	    Thread.sleep(2000);
	    Assert.assertTrue(driver.getTitle().startsWith("Order Confirmation"));	       
	}
	
	@Test(enabled=false)
	public void testCase_10A_Choose_Shipping_Method() throws InterruptedException{
		//iF 8 pass --> 10A pass
	}
	
	
	
	
	
	@Test
	public void testCase_12B_Update_Boating(){
		//Verify user can update Boating info
		MethodAction.login(driver, username, password);
        driver.findElement(By.className("my_account_menu")).click();
        driver.findElement(By.id("my_account_list")).findElement(By.linkText("My Info")).click();
        //Assert.assertTrue("My Info", driver.getPageSource().contains("My Info"));
        driver.findElement(By.id("editpassword")).click();
        driver.findElement(By.id("profile.currentPassword")).sendKeys("Ilove12345678");
        driver.findElement(By.id("profile-newPassword")).sendKeys("Ilove12345678");
        driver.findElement(By.id("profile.checkNewPassword")).sendKeys("Ilove12345678");
        driver.findElement(By.className("form_field-button-float")).findElement(By.xpath("//button[@type='submit']")).click();
      
        driver.findElement(By.id("editpersonalinfo")).click();
        driver.findElement(By.id("address.firstName")).clear();
        driver.findElement(By.id("address.firstName")).sendKeys("First " + new Date().getTime() % 100);
        driver.findElement(By.id("address.surname")).clear();
        driver.findElement(By.id("address.surname")).sendKeys("Last " + new Date().getTime() % 100);
        driver.findElement(By.id("address.line1")).clear();
        driver.findElement(By.id("address.line1")).sendKeys("Address " + new Date().getTime() % 100);
        driver.findElement(By.id("address.townCity")).clear();
        driver.findElement(By.id("address.townCity")).sendKeys("City " + new Date().getTime() % 100);
        selectState = new Select(driver.findElement(By.id("address.region")));
        selectState.selectByValue("US-CA");
        driver.findElement(By.id("address.postcode")).clear();
        driver.findElement(By.id("address.postcode")).sendKeys("94108");
        driver.findElement(By.id("address.phoneNumber_del")).clear();
        driver.findElement(By.id("address.phoneNumber_del")).sendKeys("55" +new Date().getTime()% 1000000000);
        driver.findElement(By.className("change_address_button")).click();
       // Assert.assertTrue("Info Updated", driver.getPageSource().contains("You have successfully updated your personal info."));
        
        driver.findElement(By.id("editmarketinginfo")).click();
        driver.findElement(By.id("I would like to be notified of news, events and special offers via email.")).click();
        driver.findElement(By.id("I would like to be notified of news, events and special offers via postal mail.")).click();
        driver.findElement(By.className("form_field-button-float")).findElement(By.xpath("//button[@type='submit']")).click();
        Assert.assertTrue("Notifications Updated", driver.getPageSource().contains("Promotional Preferences has been saved."));
        
        driver.findElement(By.id("editboatinginfo")).click();
        Select selectBoatQty = new Select(driver.findElement(By.id("answerBoatQuantity")));
        selectBoatQty.selectByValue("4");
        Select selectBoatType = new Select(driver.findElement(By.id("answerBoatType")));
        selectBoatType.selectByValue("Power");
        driver.findElement(By.id("register.boatLength")).clear();
        driver.findElement(By.id("register.boatLength")).sendKeys("2"+new Date().getTime() % 1);
        Select selectBoatPrimaryUse = new Select(driver.findElement(By.id("answerBoatPrimaryUsage")));
        selectBoatPrimaryUse.selectByValue("Paddlesports (kayak, canoe)");
        Select selectBoatSecondaryUse = new Select(driver.findElement(By.id("answerBoatSecondaryUsage")));
        selectBoatSecondaryUse.selectByValue("Paddlesports (kayak, canoe)");
        driver.findElement(By.tagName("button")).click();
        Assert.assertTrue("Boating Questions Updated", driver.getPageSource().contains("The Boating Information was successfully updated"));

	}
	
	
	
	@Test(enabled=true)
	public void testCase_11B_edit_payment(){
		//Verify user can edit payment details
		MethodAction.login(driver, username, password);
        driver.findElement(By.linkText("Manage your payment details")).click();
        driver.findElement(By.linkText("Edit")).click();
        WebElement firstName = driver.findElement(By.id("address.firstName"));
        String expected = "Ok"+new Date().getTime() % 100000;
        firstName.clear();
        firstName.sendKeys(expected);
        driver.findElement(By.id("cardNumber")).clear();
        driver.findElement(By.id("cardNumber")).sendKeys("4111111111111111");
        driver.findElement(By.id("lastInTheForm")).click();
        assertTrue(driver.getTitle().equals("Payment Details | West Marine"));
        assertTrue(driver.getPageSource().contains(expected));
	}
	
	@Test(enabled=true)
	public void testCase_11C_delete_payment(){
		//Verify user can delete payment details
		MethodAction.login(driver, username, password);
        driver.findElement(By.linkText("Manage your payment details")).click();
        driver.findElement(By.linkText("Remove")).click();
        driver.getPageSource().contains("Payment Card removed successfully");
	}
	
	@Test(enabled=true)
	public void testCase_11A_Add_payment() throws InterruptedException{
		//Verify user can update payment details
		MethodAction.login(driver, username, password);
        driver.findElement(By.linkText("Manage your payment details")).click();
        MethodAction.myAccountPaymentDetailAddNewCardClick(driver);
        Thread.sleep(1500);
        MethodAction.myAccountEnterShippingAddreesForPayment(driver, "United States",
				"firstN", "lastN", "8320", "", "Tempe", 
				"Arizona", "85284", "2818185768");
        Random rand = new Random();
        long r = rand.nextInt(60000) + 100000;
        MethodAction.myAccountEnterNewCard(driver, CardType.Visa, "4111111111"+r, "11","2016","Vu Nguyen");       
        driver.findElement(By.id("lastInTheForm")).click();
        driver.getPageSource().contains("The Payment information has been added");
        
	}

	@Test
	public void testCase_8B_register_after_checkout(){
		//Verify guest can register after checkout
		//If 8B pass --> 8A Pass
		Date date= new Date();
		MethodAction.searchSkuAddToCartBachelorGoToCartGoToCheckout(driver, "13194626",1);
		MethodAction.loginAsGuest(driver, date.getTime()+username);
		MethodAction.deliveryShippingAddreesEnterShippingAddress(driver, "United States",
				"firstN", "lastN", "8320", "", "Tempe", 
				"Arizona", "85284", "2818185768");
		MethodAction.deliveryShippingAddressContinueClick(driver);
		MethodAction.deliveryShippingMethodOptionSelect(driver, 1);
		MethodAction.deliveryShippingMethodContinueClick(driver);
		MethodAction.paymentMethodEnterNewCard(driver, CardType.Visa, "6011577019999920",
				"999","12","2015","Vu Nguyen", "11","11","11" );
		MethodAction.paymentMethodContinueClick(driver);
		MethodAction.paymentMethodEnterNewCard(driver, CardType.Visa, "4111111111111111",
				"999","12","2015","Vu Nguyen", "11","11","11" );
		MethodAction.paymentMethodContinueClick(driver);
		MethodAction.summaryPlaceOrderClick(driver);
		
		assertEquals("Thank you for your purchase", driver.findElement(By.xpath("//div[@id='content']/div[3]/h1")).getText());
		
		driver.findElement(By.id("password")).sendKeys("Ilove12345678");
		driver.findElement(By.id("guest.checkPwd")).sendKeys("Ilove12345678");
		driver.findElement(By.xpath("//form[@id='guestRegisterForm']/div[2]/button")).click();
		
	}
	
	@Test(enabled=true)
	public void testCase_13A_Social_Network(){
		//Verify user can share on social networks a product
		MethodAction.searchSku(driver, "13194626");
		driver.findElement(By.xpath("/html/body/div[3]/div[2]/div[2]/div[1]/div[2]/div/div/a[1]/span")).click();;
		for (String winHandle : driver.getWindowHandles()) {
		    driver.switchTo().window(winHandle); 
		    if (driver.getTitle().equals("Facebook")){
		    	break;
		    }
		}
		driver.findElement(By.id("email")).sendKeys("nd9593@gmail.com");
		driver.findElement(By.id("pass")).sendKeys("123456");
		driver.findElement(By.id("u_0_1")).click();
		driver.findElement(By.xpath("/html/body/div[1]/form/div[2]/div[1]/button[2]")).click();
	}
	
	@Test
	public void testCase_14A_B_C_MyList() throws InterruptedException{
		// Verify user can add product to list
		MethodAction.login(driver, username, password);
		MethodAction.searchSku(driver, "565096");		 
		Browser.driver.findElement(By.linkText("Add to My List")).click();
		MethodAction.searchSku(driver, "3837598");
		Browser.driver.findElement(By.linkText("Add to My List")).click();
		Thread.sleep(3000);
		Browser.driver.findElement(By.linkText("View My List")).click();
		
		Browser.driver.findElement(By.xpath("/html/body/div[3]/div[2]/div[2]/div[4]/div[2]/div[2]/div/div[2]/div[2]/form/button")).click();
		Thread.sleep(1500);
		Browser.driver.findElement(By.xpath("/html/body/div[3]/div[2]/div[2]/div[4]/div[2]/div/div/div[2]/div[2]/form/button")).click();
	}
	
	
	@Test
	public void testCase_16B_upgrade_Membership_No_Gold(){
		//No member To Gold  

  		String email = MethodUtil.uniqueEmailStr();
  		String password = "Ilove12345678";
  		String checkPwd = "Ilove12345678";
  		String firstName = "Vu" + (new Date()).getTime();
  		String lastName = "Nguyen";
  		String country = "United States";
  		String line1 = "8320";
  		String line2 = "";
  		String townCity = "Tempe";
  		String region = "Arizona" ;
  		String postcode = "85284";
  		String phone = "2818185768";
  		MethodAction.registerEnterNewUser(driver, email, password, checkPwd, firstName, lastName, country, line1, line2, townCity, region, postcode, phone);
  		MethodAction.registerClickSubmitButton(driver);
		driver.findElement(By.linkText("West Advantage Rewards")).click();
		driver.findElement(By.className("link_button_positive")).click();
		driver.findElement(By.xpath("//div[@id='content']/div[4]/div[3]/div[1]/div[2]/div/div/a")).click();
		driver.findElement(By.id("gold.unlimitedTrailerAssist")).click();
		driver.findElement(By.id("freshwaterTowing")).click();
		driver.findElement(By.id("gold-agree-checkbox")).click();
		driver.findElement(By.id("gold-submit-button")).click();
		driver.findElement(By.id("checkoutButtonTop")).click();
		MethodAction.deliveryShippingAddressContinueClick(driver);	
		
		assertTrue("No Methods)", driver.getPageSource().contains("You will receive information about your West Advantage Membership within 1 - 2 weeks."));
		assertTrue(driver.getPageSource().contains("You will receive information about your West Advantage Membership within 1 - 2 weeks."));
		MethodAction.deliveryShippingMethodContinueClick(driver);
		MethodAction.paymentMethodEnterNewCard(driver, CardType.Visa, "4111111111111111",
				"999","12","2015","Vu Nguyen", "11","11","11" );
		MethodAction.deliveryShippingMethodContinueClick(driver);
		MethodAction.summaryPlaceOrderClick(driver);
		Assert.assertTrue("Starts with Order Confirmation", driver.getTitle().startsWith("Order Confirmation"));
	}
	
	@Test
	public void testCase_16A_upgrade_Membership_Silver_Gold(){
		//No member To Gold  
  		String email = MethodUtil.uniqueEmailStr();
  		String password = "Ilove12345678";
  		String checkPwd = "Ilove12345678";
  		String firstName = "Vu" + (new Date()).getTime();
  		String lastName = "Nguyen";
  		String country = "United States";
  		String line1 = "8320";
  		String line2 = "";
  		String townCity = "Tempe";
  		String region = "Arizona" ;
  		String postcode = "85284";
  		String phone = "2818185768";
  		MethodAction.registerEnterNewUser(driver, email, password, checkPwd, firstName, lastName, country, line1, line2, townCity, region, postcode, phone, true, true, LoyaltyType.SILVER);
  		MethodAction.registerClickSubmitButton(driver);
		driver.findElement(By.linkText("West Advantage Rewards")).click();
		driver.findElement(By.className("link_button_positive")).click();
		driver.findElement(By.xpath("//div[@id='content']/div[4]/div[3]/div[1]/div[2]/div/div/a")).click();
		driver.findElement(By.id("gold.unlimitedTrailerAssist")).click();
		driver.findElement(By.id("freshwaterTowing")).click();
		driver.findElement(By.id("gold-agree-checkbox")).click();
		driver.findElement(By.id("gold-submit-button")).click();
		driver.findElement(By.id("checkoutButtonTop")).click();
		MethodAction.deliveryShippingAddressContinueClick(driver);	
		
		assertTrue("No Methods)", driver.getPageSource().contains("You will receive information about your West Advantage Membership within 1 - 2 weeks."));
		assertTrue(driver.getPageSource().contains("You will receive information about your West Advantage Membership within 1 - 2 weeks."));
		MethodAction.deliveryShippingMethodContinueClick(driver);
		MethodAction.paymentMethodEnterNewCard(driver, CardType.Visa, "4111111111111111",
				"999","12","2015","Vu Nguyen", "11","11","11" );
		MethodAction.deliveryShippingMethodContinueClick(driver);
		MethodAction.summaryPlaceOrderClick(driver);
		Assert.assertTrue("Starts with Order Confirmation", driver.getTitle().startsWith("Order Confirmation"));
	
	}
	
	@Test
	public void testCase_17A_giftcard() throws InterruptedException{
		// Verify user can add configured gift card to his cart 
		driver.navigate().to("http://qr-hybris.westmarine.net/giftCard/eGiftCardLayoutPage");
        driver.findElement(By.id("recipientName")).sendKeys("Selenium Test Recipient");
        driver.findElement(By.id("recipientEmail")).sendKeys("vun@westmarine.com");
        driver.findElement(By.id("recipientEmail2")).sendKeys("vun@westmarine.com");
        driver.findElement(By.id("eGiftProductCode_10115038")).click();
        driver.findElement(By.id("privateMessage")).sendKeys("This is a Selenium Automated test, this email will be sent");
        driver.findElement(By.id("EGiftCardDesign_5")).click();
        driver.findElement(By.id("senderName")).sendKeys("Selenium Test Sender");
        driver.findElement(By.id("senderEmail")).sendKeys("vun@gmail.com");
        driver.findElement(By.id("senderEmail2")).sendKeys("vun@gmail.com");
        driver.findElement(By.className("eGiftCardPreviewLink")).click();
  
        Thread.sleep(2000);
        driver.findElement(By.id("egiftcard-preview-add-button")).click();

        driver.findElement(By.id("checkoutButtonTop")).click();
        MethodAction.loginAsGuest(driver, username);

        MethodAction.deliveryShippingAddreesEnterShippingAddress(driver, "United States",
				"firstN", "lastN", "8320", "", "Tempe", 
				"Arizona", "85284", "2818185768");
        MethodAction.deliveryShippingAddressContinueClick(driver);
        Assert.assertTrue(driver.getPageSource().contains("You have an eGift Card(s) in your order.  The recipient will receive their eGift Card via email."));

        MethodAction.deliveryShippingMethodContinueClick(driver);
		MethodAction.paymentMethodEnterNewCard(driver, CardType.Visa, "4111111111111111",
				"999","12","2015","Vu Nguyen", "11","11","11" );
		MethodAction.deliveryShippingMethodContinueClick(driver);
		MethodAction.summaryPlaceOrderClick(driver);
		Assert.assertTrue("Starts with Order Confirmation", driver.getTitle().startsWith("Order Confirmation"));
	
	}
	
	@Test
	public void testCase_15A_Track_orders(){
		//Verify orders and order details
		driver.get("https://qr-hybris.westmarine.net/guest/order/tracking");
		driver.findElement(By.id("order.guest.tracking.orderNumber")).sendKeys("14449989");
		driver.findElement(By.id("order.guest.tracking.lastName")).sendKeys("LASTN ");
		driver.findElement(By.xpath("//form[@id='guestOrderTrackingForm']/div/div/div[4]/button")).click();
		String orderDetails = driver.findElement(By.xpath("/html/body/div[3]/div[2]/div[2]/div[2]/div[1]/div[1]/h1")).getText();
		assertEquals ("Order Details", orderDetails);
				
	}
	
	@Test
	public void testCase_3A_Login(){
		//Normal login
		MethodAction.login(driver, username, password);
		assertTrue(driver.getPageSource().contains("Hi"));
		
	}
	
	@Test
	public void testCase_3B_Login(){
		//login wrong password
		MethodAction.login(driver, username, password+"lll");
		assertTrue(driver.getPageSource().contains("Your username or password was incorrect."));
		
	}
	
	@Test
	public void testCase_3C_Login(){
		//login wrong password
		MethodAction.login(driver, username+"vn", password);
		assertTrue(driver.getPageSource().contains("Your username or password was incorrect."));
		
	}
	
	
	@AfterMethod
	public void afterMethod() throws IOException, AWTException{
		//Browser.driver.close();
		screenRecorder.stop();
	}

 
}


	   

